#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e3+10;
int n,m,a[N][N],u[N][N],d[N][N],lf[N][N],rt[N][N],sum[N],ans;
string s;
signed main(){
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>s;
		s=" "+s;
		for(int j=1;j<=m;j++)
			a[i][j]=s[j]-'a'+1;
	}
	for(int i=1;i<=m;i++)
		for(int j=n;j>=1;j--)
			if(a[j][i]!=a[j+1][i]) d[j][i]=1;
			else d[j][i]=d[j+1][i]+1;
	for(int i=1;i<=n;i++)
		for(int j=m;j>=1;j--)
			if(a[i][j]!=a[i][j+1]) rt[i][j]=1;
			else rt[i][j]=rt[i][j+1]+1;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			memset(sum,0,sizeof(sum));
			for(int k=1;k<=m;k++){
				sum[k]=sum[k-1];
				if(i+d[i][k]-1>=j) sum[k]++;
			}
			for(int k=1;k<=m;k++)
				if(i+d[i][k]-1>=j) ans+=sum[k+min(rt[i][k],rt[j][k])-1]-sum[k];
		}
	cout<<ans;
	return 0;
}